/**
 * <p>员工信息类</p>
 * @author huangjian
 * @createDate 2015-08-31 下午 16:58:58
 * @version V1.0
 */
CommonUtils.regNamespace("user", "index");
user.index = (function(){
	//查询用户信息，并验证
	var _queryUserById = function(){
		var userName = $("#userName").val();
		var userPassword = $("#userPassword").val();
		if(userName==null||userName==""){
			alert("请输入用户名");
			return;
		}
		if(userPassword==null||userPassword==""){
			alert("请输入用户密码");
			return;
		}
		var params = {
				"userName":userName,
				"userPassword":userPassword
				};
		var contextPath= path+"/user/queryUserById";
		$.ajax({
	        type:"POST",
	        url:contextPath,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "json",
	        async:false,
	        success:function(respone){
	        	if(respone){
	        		if(respone.code==0){
	        			//将用户的信息放在全局变量中
	        			user.info.userdata.userName = respone.data.userName;
	        			user.info.userdata.userId = respone.data.userId;
	        			user.info.userdata.roleIds = respone.data.roleIds;
	        			window.location.href = path+"/user/home";
	        		}else{
	        			/*Lobibox.alert('error', {
	                        msg: respone.errorsList
	                    });*/
	        			alert(respone.errorsList);
	        		}
	        	}else{
	        		alert("登录失败");
	        	}
	        },error:function(respone){
	            alert("请求发生错误:"+respone);
	        }
	    });
	};
	var _registerUser = function(){
		var userName = $("#reUserName").val();
		if(userName==""||userName==null){
			alert("请输入用户名...");
			return;
		}
		var	userPwd = $("#userPwd").val();
		if(userPwd==""||userPwd==null){
			alert("请输入用户密码...");
			return;
		}
		var params = {
			"userName":userName,
			"userPwd":userPwd
		}
		var contextPath =path +"/user/registerUser";
		$.ajax({
	        type:"POST",
	        url:contextPath,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "json",
	        async:false,
	        success:function(respone){
	        	if(respone){
	        		if(respone.code==0){
	        			//跳转至登录界面
	        			alert("注册成功，跳转至登录页面....")
	        			window.location.href = path+"/user/login";
	        		}else{
	        			Lobibox.alert('error', {
	                        msg: respone.message
	                    });
	        		}
	        	}else{
	        		alert("注册失败");
	        	}
	        },error:function(respone){
	            alert("请求发生错误:"+respone);
	        }
	    });
	}
	//查询主页功能信息
	var _queryUserFunction=function(){
		
	};
	return{
		queryUserById:_queryUserById,
		queryUserFunction:_queryUserFunction,
		registerUser:_registerUser
	};
})();

$(function(){
	//回车提交事件
	$("body").keydown(function() {
	    if (event.keyCode == "13") {//keyCode=13是回车键
	    	user.index.queryUserById();
	    }
	});
});